package com.ymatou.iapi.godmch.testcase;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.RemoveCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.RemoveCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
/**
*作废邀请码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RemoveCode{
	private static RemoveCodeBean bean;
	private static RemoveCodeCall call;
	 private invite_codeWapper inviteCodeWapper=new invite_codeWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("作废邀请码");
	}

	@Before
	public void caseUp() {
		bean=new RemoveCodeBean();
		call=new RemoveCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_001() {
		Logger.start(true,"作废邀请码,验证永久用效");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId());
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_002() {
		Logger.start(true,"作废邀请码,验证不是永久用效");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId());
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_003() {
		Logger.start(true,"作废邀请码,验证已经作废了,再次作废,返回错误,邀请码不存在");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId());
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			call.callService();
			//验证点
	        Logger.verifyEquals("5011", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_004() {
		Logger.start(true,"作废邀请码,验证商户Id与邀请码不一致,返回错误");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			
			CreateCodeBean codebean2=GodmchManageCallService.CreateAllMsgSellerMch();
			CreateCodeCall codeCall2=GodmchManageCallService.createCodeCall(codebean2);

			bean.setMchId(codebean2.getMchId());
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("5011", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_005() {
		Logger.start(true,"作废邀请码,验证商户Id不存在,返回错误");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId()+9999);
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("5011", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_006() {
		Logger.start(true,"作废邀请码,验证邀请码不存在,返回错误");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId());
			bean.setCode(codeCall.getCode()+9999);
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("5011", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功Message值");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_007() {
		Logger.start(true,"作废邀请码,验证商户Id为空,返回错误");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(null);
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("商户id不能为空"), "验证返回成功Message值");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_008() {
		Logger.start(true,"作废邀请码,验证邀请码为空,返回错误");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			bean.setMchId(codebean.getMchId());
			bean.setCode(null);
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RemoveCode_009() {
		Logger.start(true,"作废邀请码,验证邀请码已过期,返回正确");
		try {
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

//			invite_code model2=inviteCodeWapper.selectByPrimaryKey(Integer.parseInt(codeCall.getCode()));
			invite_code model2=inviteCodeWapper.selectByCode(codeCall.getCode());
			Calendar Cal=java.util.Calendar.getInstance();   
	        Cal.setTime(model2.getCreateTime());   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,-2);  //目前配置一天后过期 
	        inviteCodeWapper.updateExpireByCode(codeCall.getCode(), Cal.getTime());
	        
			bean.setMchId(codebean.getMchId());
			bean.setCode(codeCall.getCode());
			call.setData(bean);
			call.callService();			
			//验证点
	        Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}